//
// Created by twetec on 25-8-16.
//

#ifndef NETWORK_PROBER_BACKUP_TEST_HANDLE_TELNET_BACKUP_TEST_H
#define NETWORK_PROBER_BACKUP_TEST_HANDLE_TELNET_BACKUP_TEST_H

#include <future>

namespace boost::json
{
struct value_from_tag;
struct value;
}

namespace network_prober::backup_test
{
/**
 * TELNET IPv4 测试结果
 */
struct TELNETBackupTestResultIPv4
{
    std::string interface;
    std::string target;
    std::uint16_t port;
    std::string backupData;

    // 自定义输出
    friend std::ostream& operator<<(std::ostream& out, const TELNETBackupTestResultIPv4& result);
};

/**
 * TELNET IPv4 测试结果 序列化
 * 注：保证 tag_invoke函数 与 ICMPProbeDetectResult类 在同一个命名空间
 */
void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, TELNETBackupTestResultIPv4 const &c);

/**
 * 测试参数
 * {"interface":"192.168.0.101","address":"192.168.0.1","backupDate":"12:30:15", "protocol": 1,"command":"mkdir test","account":"admin","password":"123456","privilegedPassword":"admin123456","port":8080}
 */
struct TELNETBackupTestParamsIPv4
{
    std::string_view interface;
    std::string_view target;
    std::uint16_t port;
    std::string_view username;
    std::string_view password;
    std::string_view privilegedPassword;
    std::string_view command;
};

/**
 * TELNET IPv4
 */
class HandleTELNETBackupTestIPv4 : public std::enable_shared_from_this<HandleTELNETBackupTestIPv4>
{
public:
    /**
     *  探测
     */
    void test();

    /**
     * 探测到时回调
     */
    void setOnTestedCallback(std::function<void(TELNETBackupTestResultIPv4&&)> callback);

    /**
     * @param interface 网口地址
     * @param target 目标地址
     */
    HandleTELNETBackupTestIPv4(TELNETBackupTestParamsIPv4&& testParams);
    ~HandleTELNETBackupTestIPv4();

private:
    std::string m_interface;
    std::string m_target;
    std::uint16_t m_port;
    std::string m_username;
    std::string m_password;
    std::string m_privilegedPassword;
    std::string m_command;
    std::function<void(TELNETBackupTestResultIPv4&&)> m_onTestedCallback;
    std::future<void> m_onTestedCallbackFuture;
};

/**
 * TELNET IPv6 测试结果
 */
struct TELNETBackupTestResultIPv6
{
    std::string interface;
    std::string target;
    std::uint16_t port;
    std::string backupData;
};

/**
 * TELNET IPv6 测试结果 序列化
 * 注：保证 tag_invoke函数 与 ICMPProbeDetectResult类 在同一个命名空间
 */
void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, TELNETBackupTestResultIPv6 const &c);

/**
 * 测试参数
 * {"interface":"192.168.0.101","address":"192.168.0.1","backupDate":"12:30:15", "protocol": 1,"command":"mkdir test","account":"admin","password":"123456","privilegedPassword":"admin123456","port":8080}
 */
struct TELNETBackupTestParamsIPv6
{
    std::string_view interface;
    std::string_view target;
    std::uint16_t port;
    std::string_view username;
    std::string_view password;
    std::string_view privilegedPassword;
    std::string_view command;
};

/**
 * TELNET IPv6
 */
class HandleTELNETBackupTestIPv6 : public std::enable_shared_from_this<HandleTELNETBackupTestIPv6>
{
public:
    /**
     *  探测
     */
    void test();

    /**
     * 探测到时回调
     */
    void setOnTestedCallback(std::function<void(TELNETBackupTestResultIPv6&&)> callback);

    /**
     * @param interface 网口地址
     * @param target 目标地址
     */
    HandleTELNETBackupTestIPv6(TELNETBackupTestParamsIPv6&& testParams);
    ~HandleTELNETBackupTestIPv6();

private:
    std::string m_interface;
    std::string m_target;
    std::uint16_t m_port;
    std::string m_username;
    std::string m_password;
    std::string m_privilegedPassword;
    std::string m_command;
    std::function<void(TELNETBackupTestResultIPv6&&)> m_onTestedCallback;
    std::future<void> m_onTestedCallbackFuture;
};

}


#endif //NETWORK_PROBER_BACKUP_TEST_HANDLE_TELNET_BACKUP_TEST_H
